using Godot;

public partial class Debug : Label
{
    private CharacterBody3D player;
    private VoxelWorld voxelWorld;

    public override void _Ready()
    {
        player = GetNode<CharacterBody3D>("../Player");
        voxelWorld = GetNode<VoxelWorld>("../VoxelWorld");
    }

    public override void _Process(double delta)
    {
        if (Input.IsActionJustPressed("debug"))
        {
            Visible = !Visible;
        }

        var text = $"Position{player.Transform.Origin} \n" +
        $"Effective render distance {voxelWorld.effectiveRenderDistance} \n" +
        $"Looking {CardinalStringFromRadians(player.Transform.Basis.GetEuler().Y)} \n" +
        $"Memory {OS.GetStaticMemoryUsage() / 1048576.0,3:F0} MiB \n" +
        $"FPS {Engine.GetFramesPerSecond()} ";

    }

    private string CardinalStringFromRadians(float angle)
    {
        if (angle > double.Tau * 3 / 8)
        {
            return "South";
        }
        if (angle < -double.Tau * 3 / 8)
        {
            return "South";
        }
        if (angle > double.Tau * 1 / 8)
        {
            return "West";
        }
        if (angle < -double.Tau * 1 / 8)
        {
            return "East";
        }
        return "North";
    }
}

